const app = getApp()
Page({
  data: {
    userName: '',
    userDept: '',
    stuState: -1
  },
  onShow: function(options) {
    this.setData({
      userName: app.globalData.userName,
      userDept: app.globalData.userDept,
      stuState: app.globalData.userState
    })
  },
  funXt: function() {
    wx.cloud.database({
      env: 'gtss-2b1812'
    }).collection('Option').where({
      userId: app.globalData.userId
    }).count().then(res => {
      if (res.total > 0) {
        wx.navigateTo({
          url: '../stuDskt/stuDskt?from=stuWd'
        })
      } else {
        wx.showToast({
          title: '您还未申请任何选题',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  funKt: function() {
    wx.cloud.database({
      env: 'gtss-2b1812'
    }).collection('Student').doc(app.globalData.userId).field({
      stuTopicId: true
    }).get().then(res => {
      wx.navigateTo({
        url: "../stuKtxq/stuKtxq?_id=" + res.data.stuTopicId + '&ffrom=stuWdkt'
      })
    })
  },
  funPas: function() {
    wx.navigateTo({
      url: '../changePas/changePas'
    })
  },
  funGg: function() {
    wx.cloud.database({
      env: 'gtss-2b1812'
    }).collection('Notice').where({
      dept: app.globalData.userDept
    }).count().then(res => {
      if (res.total > 0) {
        wx.navigateTo({
          url: '../notice/notice'
        })
      } else {
        wx.showToast({
          title: '管理员未发布任何公告',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  funXx: function() {
    wx.cloud.database({
      env: 'gtss-2b1812'
    }).collection('Message').where({
      receiveId: app.globalData.userId
    }).count().then(res => {
      if (res.total > 0) {
        wx.navigateTo({
          url: '../message/message'
        })
      } else {
        wx.showToast({
          title: '您还没收到任何消息',
          icon: 'none',
          duration: 2000
        })
      }
    })
  }
})